package cn.tedu.shoot;

import cn.tedu.submarine.Bomb;

import java.awt.image.BufferedImage;

public class Hero extends FlyingObject{
    int life;
    int fire;
    public Hero(){
        super(97,139,140,400);
        life = 3;
        fire = 0;
    }

    public void step(){

    }

    private int index = 0;
    public BufferedImage getImage(){
        return Images.heros[index++%Images.heros.length];
    }

    /**
     * 英雄机发射子弹，创建子弹对象
     * @return 子弹对象
     */
    public Bullet[] shoot(){
        int xStep = this.width/4;
        int yStep = 20;
        if(fire>0){
            Bullet[] bs = new Bullet[2];
            bs [0] = new Bullet(this.x+1*xStep,this.y-yStep);
            bs [1] = new Bullet(this.x+3*xStep,this.y-yStep);
            fire -=2;
            return bs;
        }else{
            Bullet[] bs = new Bullet[1];
            bs [0] = new Bullet(this.x+2*xStep,this.y-yStep);
            return bs;
        }
    }

    public void moveTo(int x,int y){
        this.x = x -this.width/2;
        this.y = y-this.height/2;
    }
}
